<?php

namespace Admin\Controller;

use Common\Controller\AdminBaseController;

/**
 * 后台首页控制器
 */
class OrderController extends AdminBaseController {
    /**
     * 首页
     */
    public function index() {
        $order_date = @empty($_GET['order_date']) ? date("Y-m-d", time()) : $_GET['order_date'];
        //        $order_date = '2018-10-17';
        $condition = array();
        $condition['order_date'] = $order_date;
        //        $condition['order_date'] = $order_date;

//        $oderList = M("order")->where($condition)->select();
//        $oderList = M("order")->join('left join canteen_item on canteen_order.item_id=canteen_item.item_id) left join canteen_item_class on canteen_item_class.item_type_id=canteen_item.item_type ')->where('canteen_order.order_date = '.$order_date)->order('canteen_item_class.item_type_sort asc,canteen_item.item_sort asc')->select();

        $oderList = M("order")->query("select *from (canteen_order left join canteen_item on canteen_order.item_id=canteen_item.item_id) left join canteen_item_class on canteen_item_class.item_type_id=canteen_item.item_type where canteen_order.order_date = '{$order_date}' order by  canteen_item_class.item_type_sort asc,canteen_item.`item_sort` asc ");

        $itemList = array();
        $bookMemberList = array();
        foreach ($oderList as $preOrder) {
            $bookMemberList[$preOrder['member_id']] = true;
            $num = 0;
            if (!empty($itemList[$preOrder['item_id']])) {
                $num = $itemList[$preOrder['item_id']]['item_number'];
            }
            $itemList[$preOrder['item_id']] = array('item_name' => getItemName($preOrder['item_id']), 'item_number' => $preOrder['item_number'] + $num, 'unit_name' => getItemUnitName($preOrder['item_id']), 'item_id' => $preOrder['item_id'], 'item_price' => $preOrder['pre_price'], 'item_buy_price' => $preOrder['buy_price'], 'item_total' => 0,);
        }
        $canteenList = M("canteen")->where(array('canteen_status'=>1))->select();
        foreach ($canteenList as $k => $canteenInfo) {
            $canteenList[$k]['total'] = count(M("member")->where(array('canteen_id' => $canteenInfo['canteen_id']))->select());
            $canteenList[$k]['book'] = 0;
            $canteenList[$k]['memberList'] = M("member")->where(array('canteen_id' => $canteenInfo['canteen_id']))->select();
            if (!empty($canteenList[$k]['memberList'])) {
                foreach ($canteenList[$k]['memberList'] as $member) {
                    if ($bookMemberList[$member['member_id']] == true) {
                        $canteenList[$k]['book']++;
                    }
                }
            }
        }
        $memberList = M("member")->select();
        foreach ($memberList as $k=>$member){
            $oderk[$k] = M("order")->where(array('order_date'=>$order_date,'member_id'=>$member['member_id']))->select();
            if(empty($oderk[$k])){
                unset($memberList[$k]);
                continue;
            }
            $memberList[$k]['canteen_name'] = getCanteenName($member['canteen_id']);
        }
        $this->assign('memberList', $memberList);
        $this->assign('order_date', $order_date);
        $this->assign('itemList', $itemList);
        $this->assign('canteenList', $canteenList);
        $this->display();

    }

    public function windowOrder() {
        $order_date = @empty($_GET['order_date']) ? date("Y-m-d", time()) : $_GET['order_date'];
        $member_id = intval(@$_GET['member_id']);
        if ($member_id) {
            $memberInfo = M("member")->where(array('member_id' => $member_id))->find();
            $memberInfo['canteen_name'] = getCanteenName($memberInfo['canteen_id']);
            $titleName = $order_date . $memberInfo['window_name'] . "订单";
            $condition = array();
            $condition['member_id'] = $memberInfo['member_id'];
            $condition['order_date'] = $order_date;

            $orderList = M("order")->where($condition)->select();
            foreach ($orderList as $k => $order) {
                $orderList[$k]['type_name'] = getItemTypeNameByItemId($order['item_id']);
                $orderList[$k]['item_name'] = getItemName($order['item_id']);
                $orderList[$k]['item_unit_name'] = getItemUnitName($order['item_id']);

            }
            $this->assign('order_date', $order_date);
            $this->assign('memberInfo', $memberInfo);
            $this->assign('titleName', $titleName);
            $this->assign('orderList', $orderList);
            $this->display();
        }
        else {
            $this->error("参数错误，没有找到当前的档口订单信息");
        }


    }

    public function saveEditWindowOrder() {
        $order_date = $_POST['order_date'];
        $list = $_POST['order'];
        foreach ($list as $k => $l) {
            $updata = array();
            $updata['item_order_id'] = $k;
            $updata['item_number'] = $l['number'];
            $updata['order_date'] = $order_date;
            M("order")->save($updata);
        }
        $this->success("保存成功");
        if (!$order_date || !$list) {
            $this->error("参数错误，请联系管理员");
        }
    }

    /**
     * elements
     */
    public function saveOrderPrice() {
        $orderDate = $_POST['orderDate'];
        if (!$orderDate) {
            $this->error('提交失败，请联系管理员');
            exit;
        }

        $itemList = $_POST['itemList'];
        foreach ($itemList as $item_id => $item) {
//            if (!$item['price']) {
//                $this->error('提交失败，部分菜品单价不合法');
//                exit;
//            }
//            if ($item['price'] < 0) {
//                $this->error('提交失败，部分菜品单价不合法');
//                exit;
//            }
//            if (!$item['buy_price']) {
//                $this->error('提交失败，部分菜品单价不合法');
//                exit;
//            }
//            if ($item['buy_price'] < 0) {
//                $this->error('提交失败，部分菜品单价不合法');
//                exit;
//            }
//            if (is_numeric($item['price']) == false) {
//                $this->error('提交失败，部分菜品单价不合法');
//                exit;
//            }
//            if (is_numeric($item['buy_price']) == false) {
//                $this->error('提交失败，部分菜品单价不合法');
//                exit;
//            }
        }
        foreach ($itemList as $item_id => $item) {
            $updateArr = array();
            $updateArr['pre_price'] = $item['price'];
            $updateArr['buy_price'] = $item['buy_price'];
            $condition = array();
            $condition['order_date'] = $orderDate;
            $condition['item_id'] = $item_id;
            M("order")->where($condition)->save($updateArr);
        }
        $this->success('保存成功', U('Admin/Order/index/order_date/' . $orderDate));

    }

    public function makeCaigou() {
        //生成采购单
        $condition = array();
        $condition['order_date'] = $_GET['order_date'];
        $order_date = $_GET['order_date'];
        $orderList = M("order")->where($condition)->select();
//        $orderList = M("order")->join('canteen_item ON canteen_item.item_id = canteen_order.item_id')->where(array('canteen_order.order_date'=>$_GET['order_date']))->order('canteen_item.item_type asc')->select();
        $orderList = M("order")->query("select *from (canteen_order left join canteen_item on canteen_order.item_id=canteen_item.item_id) left join canteen_item_class on canteen_item_class.item_type_id=canteen_item.item_type where canteen_order.order_date = '{$order_date}' order by  canteen_item_class.item_type_sort asc,canteen_item.`item_sort` asc ");

        //采购单头
        $caigou = array();
        $caigou[0][0] = '序号';
        $caigou[0][1] = '菜名';
        $caigou[0][2] = '规格';
//        $caigou[0][3] = '单价';
        $caigou[0][3] = '数量';
//        $caigou[0][5] = '金额';

        foreach ($orderList as $k => $order) {
            $num = 0;
            if (!empty($caigou[$order['item_id']])) {

                $num = $caigou[$order['item_id']][4];
            }
//            $caigou[$order['item_id']] = array(0 => $k + 1, 1 => getItemName($order['item_id']), 2 => getItemUnitName($order['item_id']), 3 => $order['buy_price'], 4 => $order['item_number'] + $num, 5 => ($order['item_number'] + $num) * $order['buy_price'],);
            $caigou[$order['item_id']] = array(0 => $k + 1, 1 => getItemName($order['item_id']), 2 => getItemUnitName($order['item_id']),3=> $order['item_number'] + $num);
        };
        foreach ($caigou as $k => $list) {
            if ($k == 0) continue;
            if ($list[3] == 0) {
                unset($caigou[$k]);
            }
        }
        $total = 0;
        foreach ($caigou as $k => $c) {
            $total = $total + $c[5];
        }
//        $caigou[] = array(0 => null, 1 => null, 2 => null, 3 => null, 4 => "合计金额", 5 => $total,);
        vendor("PHPExcel.PHPExcel");
        $objPHPExcel = new \PHPExcel();
        $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(9.3);//设置列宽度
        $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(17.17);//设置列宽度
        $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(21.07);//设置列宽度
        $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(14.17);//设置列宽度
        $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(8.5);//设置列宽度
        $objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(8.3);//设置列宽度
        $objPHPExcel->getActiveSheet()->getStyle("A3")->getAlignment()->setVertical('center');//垂直居中
        $objPHPExcel->getActiveSheet()->getStyle("B3")->getAlignment()->setVertical('center');//垂直居中
        $objPHPExcel->getActiveSheet()->getStyle("C3")->getAlignment()->setVertical('center');//垂直居中
        $objPHPExcel->getActiveSheet()->getStyle("D3")->getAlignment()->setVertical('center');//垂直居中
        $objPHPExcel->getActiveSheet()->getStyle("E3")->getAlignment()->setVertical('center');//垂直居中
        $objPHPExcel->getActiveSheet()->getStyle("f3")->getAlignment()->setVertical('center');//垂直居中
        $objPHPExcel->getActiveSheet()->getRowDimension('3')->setRowHeight(34);//设置行高度
        $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
        $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(20);
        $objPHPExcel->getActiveSheet()->getStyle("A2")->getAlignment()->setHorizontal('center');

        $objPHPExcel->getActiveSheet()->mergeCells("A1:F1");//合并单元格（如果要拆分单元格是需要先合并再拆分的，否则程序会报错）
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue("A1", '中山市轩浩农副产品配送有限公司采购单');
        $objPHPExcel->getActiveSheet()->getStyle("A1")->getFont()->setSize(20);
        $objPHPExcel->getActiveSheet()->getStyle("A1")->getAlignment()->setHorizontal('center');

        $objPHPExcel->getActiveSheet()->mergeCells("A2:F2");//合并单元格（如果要拆分单元格是需要先合并再拆分的，否则程序会报错）
        $objPHPExcel->setActiveSheetIndex(0)->setCellValue("A2", '日期：'.$_GET['order_date']);
        $objPHPExcel->getActiveSheet()->getStyle("A2")->getFont()->setSize(11);
        $objPHPExcel->getActiveSheet()->getStyle("A2")->getFont()->setBold(true);
        $objPHPExcel->getActiveSheet()->getStyle("A2")->getAlignment()->setHorizontal('center');

        $objPHPExcel->setActiveSheetIndex(0)->fromArray($caigou, '999', "A3", '', 30);
        $fileName = "采购单(" . $_GET['order_date'] . ")";
        header('pragma:public');
        header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $title . '.xls"');
        header("Content-Disposition:attachment;filename=$fileName.xls");//attachment新窗口打印inline本窗口打印
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');
        create_xls($caigou, "中山市轩浩农副产品配送有限公司采购单(" . $_GET['order_date'] . ")");
    }

    public function makePeiSong() {
        $order_date = $_GET['order_date'];
        $fileName = "配菜单(" . $order_date . ")";//文件名称

        ini_set('max_execution_time', '0');
        ini_set('memory_limit', '8000M');
        //生成配送单
        $member_list = M("member")->select();
        $canteenList = M("canteen")->field("canteen_id,canteen_name")->where(array('canteen_status' => 1))->select();
        $array = array();

        foreach ($canteenList as $k => $canteen) {
            $canteenList[$k]['memberList'] = M("member")->field("member_id,window_name,canteen_id")->where(array('canteen_id' => $canteen['canteen_id'], 'window_status' => 1))->select();
            $canteenList[$k]['memberListString'] = "";
            foreach ($canteenList[$k]['memberList'] as $m => $member) {
                $canteenList[$k]['memberListString'] .= $member['member_id'];
                if ($m < count($canteenList[$k]['memberList']) - 1) {
                    $canteenList[$k]['memberListString'] .= ',';
                }
            }
            if (!empty($canteenList[$k]['memberListString'])) {
                $condition = array();
                $condition['order_date'] = $_GET['order_date'];
                $condition['member_id'] = array('IN', $canteenList[$k]['memberListString']);
                $condition['item_number'] = array('NEQ', 0);
                $orderList = M("order")->group("item_id")->where($condition)->select();
                if (!empty($orderList)) {
                    foreach ($orderList as $o => $order) {
                        if ($o == 0) {
                            $array[$k]['name'] = $canteen['canteen_name'];
                            $array[$k]['list'][0][0] = "序号";
                            $array[$k]['list'][0][1] = "菜名";
                            $array[$k]['list'][0][2] = "规格";
                            foreach ($canteenList[$k]['memberList'] as $mk => $member) {
                                $array[$k]['list'][0][$mk + 3] = getWindowName($member['member_id']);
                            }
                        }
                        $array[$k]['name'] = $canteen['canteen_name'];
                        $array[$k]['list'][$o + 1][0] = $order['item_id'];
                        $array[$k]['list'][$o + 1][1] = getItemName($order['item_id']);
                        $array[$k]['list'][$o + 1][2] = getItemUnitName($order['item_id']);
                        foreach ($canteenList[$k]['memberList'] as $mk => $member) {
                            $array[$k]['list'][$o + 1][$mk + 3] = getItemNumber($order['item_id'], $member['member_id'], $order_date);
                        }
                    }
                }

            }

        }
        vendor("PHPExcel.PHPExcel");
        $objPHPExcel = new \PHPExcel();
        $i = 0;
        foreach ($array as $index => $cell) {
            $objPHPExcel->createSheet($i);
            $objPHPExcel->setActiveSheetIndex($i);
            $objPHPExcel->getActiveSheet()->settitle($cell['name']);
            $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(13);//设置列宽度
            $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(17);//设置列宽度
            $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(22);//设置列宽度
            $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(17);//设置列宽度
            $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(17);//设置列宽度
            $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(17);//设置列宽度
            $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(17);//设置列宽度
            $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(17);//设置列宽度
            $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(17);//设置列宽度
            $objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(17);//设置列宽度
            $objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(17);//设置列宽度
            $objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(17);//设置列宽度
            $objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(17);//设置列宽度
            $objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(17);//设置列宽度
            $objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(17);//设置列宽度
            $objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(17);//设置列宽度
            $objPHPExcel->getActiveSheet()->getStyle("A4")->getAlignment()->setVertical('center');//垂直居中
            $objPHPExcel->getActiveSheet()->getStyle("B4")->getAlignment()->setVertical('center');//垂直居中
            $objPHPExcel->getActiveSheet()->getStyle("C4")->getAlignment()->setVertical('center');//垂直居中
            $objPHPExcel->getActiveSheet()->getStyle("D4")->getAlignment()->setVertical('center');//垂直居中
            $objPHPExcel->getActiveSheet()->getStyle("E4")->getAlignment()->setVertical('center');//垂直居中
            $objPHPExcel->getActiveSheet()->getStyle("F4")->getAlignment()->setVertical('center');//垂直居中
            $objPHPExcel->getActiveSheet()->getStyle("G4")->getAlignment()->setVertical('center');//垂直居中
            $objPHPExcel->getActiveSheet()->getStyle("H4")->getAlignment()->setVertical('center');//垂直居中
            $objPHPExcel->getActiveSheet()->getStyle("I4")->getAlignment()->setVertical('center');//垂直居中
            $objPHPExcel->getActiveSheet()->getStyle("J4")->getAlignment()->setVertical('center');//垂直居中
            $objPHPExcel->getActiveSheet()->getStyle("K4")->getAlignment()->setVertical('center');//垂直居中
            $objPHPExcel->getActiveSheet()->getStyle("L4")->getAlignment()->setVertical('center');//垂直居中
            $objPHPExcel->getActiveSheet()->getStyle("M4")->getAlignment()->setVertical('center');//垂直居中
            $objPHPExcel->getActiveSheet()->getStyle("N4")->getAlignment()->setVertical('center');//垂直居中
            $objPHPExcel->getActiveSheet()->getStyle("O4")->getAlignment()->setVertical('center');//垂直居中
            $objPHPExcel->getActiveSheet()->getStyle("P4")->getAlignment()->setVertical('center');//垂直居中
            $objPHPExcel->getActiveSheet()->getStyle("Q4")->getAlignment()->setVertical('center');//垂直居中
            $objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(25);
            $objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(14);
            $objPHPExcel->getActiveSheet()->getRowDimension(3)->setRowHeight(14);//设置行高度
            $objPHPExcel->getActiveSheet()->getRowDimension(4)->setRowHeight(34);//设置行高度

            $objPHPExcel->setActiveSheetIndex($i)->setCellValue("A1", '配菜单');
            $objPHPExcel->getActiveSheet()->getStyle("A1")->getFont()->setSize(20);
            $objPHPExcel->setActiveSheetIndex($i)->setCellValue("B1", $cell['name']);
            $objPHPExcel->getActiveSheet()->getStyle("B1")->getFont()->setSize(20);
            $objPHPExcel->setActiveSheetIndex($i)->setCellValue("A2", $order_date);

            $objPHPExcel->setActiveSheetIndex($i)->fromArray($cell['list'], '999', "A3", '', 34);
            $i++;

        }
        header('pragma:public');
        header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $xlsTitle . '.xls"');
        header("Content-Disposition:attachment;filename=$fileName.xls");//attachment新窗口打印inline本窗口打印
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');
        exit;

    }


    public function makeSongCai() {

        $order_date = $_GET['order_date'];
        $fileName = "送菜单(" . $order_date . ")";//文件名称
        ini_set('max_execution_time', '0');
        ini_set('memory_limit', '8000M');
        //生成配送单
        $canteenList = M("canteen")->field("canteen_id,canteen_name")->where(array('canteen_status' => 1))->select();
        foreach ($canteenList as $k1=>$canteen){
            $canteenList[$k1]['list'] = M('member')->where(array('canteen_id'=>$canteen['canteen_id'],'window_status'=>1))->select();
            if(!empty($canteenList[$k1]['list'])){
                foreach ($canteenList[$k1]['list'] as $k2=>$window){
                    $lls = M("order")->join('canteen_item ON canteen_item.item_id = canteen_order.item_id')->where(array('canteen_order.member_id'=>$window['member_id'],'canteen_order.order_date'=>$order_date))->order('canteen_item.item_type asc')->select();
//                    $lls = M("order")->where(array('member_id'=>$window['member_id'],'order_date'=>$order_date))->select();
                    if(!empty($lls)){
                        $canteenList[$k1]['list'][$k2]['real'][0] = array('序号','菜名','规格','单价','数量','金额');
                        $thisTotal = 0;
                        foreach ($lls as $k3=>$item){
                            $canteenList[$k1]['list'][$k2]['real'][$k3+1][0] = $k3+1;
                            $canteenList[$k1]['list'][$k2]['real'][$k3+1][1] = getItemName($item['item_id']);
                            $canteenList[$k1]['list'][$k2]['real'][$k3+1][2] = getItemUnitName($item['item_id']);
                            $canteenList[$k1]['list'][$k2]['real'][$k3+1][3] = $item['pre_price'];
                            $canteenList[$k1]['list'][$k2]['real'][$k3+1][4] = $item['item_number'];
                            $canteenList[$k1]['list'][$k2]['real'][$k3+1][5] = $item['pre_price']*$item['item_number'];
                            $thisTotal = $thisTotal + ($item['pre_price']*$item['item_number']);
                        }
                        $canteenList[$k1]['list'][$k2]['real'][] = array('999','999','999','999','总金额',$thisTotal);
                    }else{
                        unset($canteenList[$k1]['list'][$k2]);
                        continue;
                    }
                }
            }else{
                continue;
            }
        }
        vendor("PHPExcel.PHPExcel");
        $objPHPExcel = new \PHPExcel();
        $i = 0;
        foreach ($canteenList as $index => $canteen) {
            $objPHPExcel->createSheet($index);
            $objPHPExcel->setActiveSheetIndex($index);
            foreach ($canteen['list'] as $index2=>$window){
                $objPHPExcel->getActiveSheet()->settitle($canteen['canteen_name']);
                if(!$window['real'])continue;
                $objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(9.18);//设置列宽度
                $objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(20);//设置列宽度
                $objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(14);//设置列宽度
                $objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(14);//设置列宽度
                $objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(14);//设置列宽度
                $objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(8.3);//设置列宽度
                $objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(8.3);//设置列宽度
                $objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(8.3);//设置列宽度
                $objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(8.3);//设置列宽度
                $objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(8.3);//设置列宽度
                $objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(8.3);//设置列宽度
                $objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(8.3);//设置列宽度
                $objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(8.3);//设置列宽度
                $objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(8.3);//设置列宽度
                $objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(8.3);//设置列宽度
                $objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(8.3);//设置列宽度
                if($index2==0){
                    $sadad = 1;
                    $thisCount = count($window['real']);

                }else{

                    $sadad = ($thisCount+2)*$i+1+1+5;
                }
                $thisCount = count($window['real']);

                $objPHPExcel->getActiveSheet()->mergeCells('A'.$sadad.':L'.$sadad);
                $objPHPExcel->setActiveSheetIndex($index)->setCellValue("A".$sadad, '中山市轩浩农副产品配送有限公司送货单（原材料）');
                $objPHPExcel->getActiveSheet()->mergeCells('A'.($sadad+1).':B'.($sadad+1));
                $objPHPExcel->setActiveSheetIndex($index)->setCellValue("A".($sadad+1), '收货单位');
                $objPHPExcel->getActiveSheet()->mergeCells('C'.($sadad+1).':F'.($sadad+1));
                $objPHPExcel->setActiveSheetIndex($index)->setCellValue("C".($sadad+1), $window['window_name']);
                $objPHPExcel->getActiveSheet()->mergeCells('I'.($sadad+1).':L'.($sadad+1));
                $objPHPExcel->setActiveSheetIndex($index)->setCellValue("I".($sadad+1), "日期：".$order_date);

                $objPHPExcel->getActiveSheet()->getStyle("A".$sadad)->getAlignment()->setVertical('center');//垂直居中
                $objPHPExcel->getActiveSheet()->getStyle("A".$sadad)->getAlignment()->setHorizontal('center');
                $objPHPExcel->getActiveSheet()->getStyle("A".($sadad+3))->getAlignment()->setVertical('center');//垂直居中
                $objPHPExcel->getActiveSheet()->getStyle("B".($sadad+3))->getAlignment()->setVertical('center');//垂直居中
                $objPHPExcel->getActiveSheet()->getStyle("C".($sadad+3))->getAlignment()->setVertical('center');//垂直居中
                $objPHPExcel->getActiveSheet()->getStyle("D".($sadad+3))->getAlignment()->setVertical('center');//垂直居中
                $objPHPExcel->getActiveSheet()->getStyle("E".($sadad+3))->getAlignment()->setVertical('center');//垂直居中
                $objPHPExcel->getActiveSheet()->getStyle("F".($sadad+3))->getAlignment()->setVertical('center');//垂直居中
                $objPHPExcel->getActiveSheet()->getStyle("G".($sadad+3))->getAlignment()->setVertical('center');//垂直居中
                $objPHPExcel->getActiveSheet()->getStyle("H".($sadad+3))->getAlignment()->setVertical('center');//垂直居中
                $objPHPExcel->getActiveSheet()->getStyle("I".($sadad+3))->getAlignment()->setVertical('center');//垂直居中
                $objPHPExcel->getActiveSheet()->getStyle("J".($sadad+3))->getAlignment()->setVertical('center');//垂直居中
                $objPHPExcel->getActiveSheet()->getStyle("K".($sadad+3))->getAlignment()->setVertical('center');//垂直居中
                $objPHPExcel->getActiveSheet()->getStyle("L".($sadad+3))->getAlignment()->setVertical('center');//垂直居中
                $objPHPExcel->getActiveSheet()->getStyle("M".($sadad+3))->getAlignment()->setVertical('center');//垂直居中
                $objPHPExcel->getActiveSheet()->getStyle("N".($sadad+3))->getAlignment()->setVertical('center');//垂直居中
                $objPHPExcel->getActiveSheet()->getStyle("O".($sadad+3))->getAlignment()->setVertical('center');//垂直居中
                $objPHPExcel->getActiveSheet()->getStyle("P".($sadad+3))->getAlignment()->setVertical('center');//垂直居中
                $objPHPExcel->getActiveSheet()->getStyle("Q".($sadad+3))->getAlignment()->setVertical('center');//垂直居中
                $objPHPExcel->getActiveSheet()->getRowDimension($sadad)->setRowHeight(25);
                $objPHPExcel->getActiveSheet()->getRowDimension($sadad+1)->setRowHeight(20);
                $objPHPExcel->getActiveSheet()->getRowDimension($sadad+2)->setRowHeight(14);//设置行高度
                $objPHPExcel->getActiveSheet()->getRowDimension($sadad+3)->setRowHeight(34);//设置行高度
                $objPHPExcel->getActiveSheet()->getStyle("A".($sadad+1))->getFont()->setBold(true);
                $objPHPExcel->getActiveSheet()->getStyle("C".($sadad+1))->getFont()->setBold(true);
                $objPHPExcel->getActiveSheet()->getStyle("I".($sadad+1))->getFont()->setBold(true);
                $objPHPExcel->getActiveSheet()->getStyle("A".($sadad+2))->getFont()->setBold(true);
                $objPHPExcel->getActiveSheet()->getStyle("B".($sadad+2))->getFont()->setBold(true);
                $objPHPExcel->getActiveSheet()->getStyle("C".($sadad+2))->getFont()->setBold(true);
                $objPHPExcel->getActiveSheet()->getStyle("D".($sadad+2))->getFont()->setBold(true);
                $objPHPExcel->getActiveSheet()->getStyle("E".($sadad+2))->getFont()->setBold(true);
                $objPHPExcel->getActiveSheet()->getStyle("F".($sadad+2))->getFont()->setBold(true);


                $objPHPExcel->getActiveSheet()->getStyle("A".$sadad)->getFont()->setSize(20);
//                $objPHPExcel->setActiveSheetIndex($index)->setCellValue("B1", $cell['name']);
                $objPHPExcel->getActiveSheet()->getStyle("B".$sadad)->getFont()->setSize(20);

                $objPHPExcel->getActiveSheet()->fromArray($window['real'], '999', "A".($sadad+2), '', 34);
//                echo "A".($sadad+2);
//                echo "<br>";
                $i++;

            }


        }
        header('pragma:public');
        header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $xlsTitle . '.xls"');
        header("Content-Disposition:attachment;filename=$fileName.xls");//attachment新窗口打印inline本窗口打印
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');
        exit;
    }

    /**
     * welcome
     */
    public function noOrder() {
        $order_date = @empty($_GET['order_date']) ? date("Y-m-d", time()) : $_GET['order_date'];
        $memberList = M("member")->where(array('window_status' => 1))->select();
        foreach ($memberList as $k => $member) {
            $orderList[$k] = M("order")->where(array('order_date' => $order_date, 'member_id' => $member['member_id']))->select();
            if (!empty($orderList[$k])) {
                unset($memberList[$k]);
                continue;
            }
            $memberList[$k]['canteen_name'] = getCanteenName($member['canteen_id']);
        }

        $this->assign('order_date', $order_date);
        $this->assign('memberList', $memberList);
        $this->display();
    }

    //1
    public function getPre($memberList, $time) {
        if ($time == -1) {
            return 1;
        }
        $plus = 0;
        foreach ($memberList as $k => $member) {
            if ($time <= $k) {
                continue;
            }
            else {
                $plus = $plus + count($member['list']) + 5;
            }

        }
        return $plus;
    }


}
